<template>
  <div class="user-management-container">
    <el-form ref="form" label-width="200px" :model="form">
      <el-form-item label="标题" prop="articleTitle">
        <el-input v-model="form.articleTitle" />
      </el-form-item>
      <el-form-item label="隐私政策" prop="articleContent">
        <fuwenben v-model="form.articleContent" />
      </el-form-item>
      <el-button class="baocun" size="medium" type="primary" @click="save">
        保存
      </el-button>
    </el-form>

    <!-- <edit ref="edit" @fetch-data="fetchData" /> -->
  </div>
</template>

<script>
  import { getList, doEdit } from '@/api/xieyi'

  import fuwenben from '../vab/editortwo/wang'
  // import Edit from './components/UserManagementEdit'

  export default {
    name: 'UserManagement',
    components: {
      fuwenben,
    },
    data() {
      return {
        form: {}, //数据来源
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        queryForm: {
          pageNum: 1,
          pageSize: 10,
          classification: 2, //分类0-协议 1-公告 2-隐私
        },
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      setSelectRows(val) {
        this.selectRows = val
      },
      handleEdit(row) {
        if (row.id) {
          this.$refs['edit'].showEdit(row)
        } else {
          this.$refs['edit'].showEdit()
        }
      },
      // handleDelete(row) {
      //   if (row.id) {
      //     this.$baseConfirm('你确定要删除当前项吗', null, async () => {
      //       const { msg } = await doDelete({ id: row.id })
      //       this.$baseMessage(msg, 'success', 'vab-hey-message-success')
      //       await this.fetchData()
      //     })
      //   } else {
      //     if (this.selectRows.length > 0) {
      //       const id = this.selectRows.map((item) => item.id).join()
      //       this.$baseConfirm('你确定要删除选中项吗', null, async () => {
      //         const { msg } = await doDelete({ id })
      //         this.$baseMessage(msg, 'success', 'vab-hey-message-success')
      //         await this.fetchData()
      //       })
      //     } else {
      //       this.$baseMessage('未选中任何行', 'error', 'vab-hey-message-error')
      //     }
      //   }
      // },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
      queryData() {
        this.queryForm.pageNum = 1
        this.fetchData()
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg } = await doEdit(this.form)
            this.$baseMessage(msg, 'success', 'vab-hey-message-success')
            this.$emit('fetch-data')

            this.close()
          }
        })
      },
      // async fetchData() {
      //   this.listLoading = true
      //   const {....
      //     data: { list, total },
      //   } = await getList(this.queryForm)
      //   this.list = list
      //   this.total = total
      //   this.listLoading = false
      // },
      async fetchData() {
        this.listLoading = true
        const res = await getList(this.queryForm)

        this.form = res.data.records[0]

        this.total = res.data.total
        this.listLoading = false
      },
    },
  }
</script>
